package com.zhang.authoritycenter.common.model.dto.sys;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.zhang.sharding.model.KingHoodDefaultSort;
import com.zhang.sharding.model.KingPageReqDTO;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Setter
@Getter
public class SystemDirectionReqDTO extends KingPageReqDTO implements KingHoodDefaultSort, Serializable {
    private static final long serialVersionUID = 1L;
    public static final String DEFAULT_COLUMN = "createTime";

    private Long id;
    /**
     * 数据编码
     */
    @NotNull(message = "数据编码不能为空")
    private String dataCode;
    /**
     * 父ID
     */
    private Long pId;
    /**
     * 数据key
     */
    @NotNull(message = "数据key")
    private String dataKey;
    /**
     * 数据名称值
     */
    @NotNull(message = "数据值不能为空")
    private String dataValue;
    /**
     * 数据名称
     */
    @NotNull(message = "数据名称不能为空")
    private String dataName;
    /**
     * 数据描述
     */
    private String dataDesc;

    /**
     * 归属类型（0：组织中心，1，商品中心）
     */
    private String belongType;

    /**
     * 属于类型arr
     */
    private List<Long> belongTypeList;
    /**
     * 是否前端显示 0显示 1不显示
     */
    //@NotNull(message="是否前端显示不能为空")
    private Integer isFrontDisplay;
    /**
     * 顺序
     */
    @NotNull(message = "顺序不能为空")
    private Integer sortNumber;
    /**
     * 状态
     */
    @NotNull(message = "状态不能为空")
    private Integer status;

    private Date createTime;

    private Date updateTime;

    private Integer version;

    private String pictures;

    @Override
    public List<OrderItem> getDefaultSort() {
        OrderItem one = OrderItem.desc(DEFAULT_COLUMN);
        return Collections.singletonList(one);
    }

    @Override
    public List<OrderItem> getTailSort() {
        return Collections.emptyList();
    }

    public void genBelongType() {
        if (!CollectionUtils.isEmpty(belongTypeList)) {
            this.belongType = belongTypeList.stream()
                    .map(Object::toString)
                    .collect(Collectors.joining(","));
        }
    }

}